/*
 * KleurBlokje.java
 *
 * Created on 2 mei 2008, 23:12
 */

package client.gui.controls.kleurschema;

import client.gui.*;
import client.gui.controls.scrabble.*;
import java.awt.*;
import javax.swing.BorderFactory;
import javax.swing.*;
import javax.swing.border.TitledBorder;

/**
 *
 * @author  Gonyo
 */
public class KleurBlokje extends KleurObject  {
    /** Creates new form KleurBlokje */
    
        Blokje b;
    JLabel lbl_Blauw = new JLabel();
    JLabel lbl_Groen = new JLabel();
    JLabel lbl_Rood = new JLabel();
    JTextField txt_Blauw = new JTextField(3);
    JTextField txt_Groen = new JTextField(3);
    JTextField txt_Rood = new JTextField(3);
    JButton btn_Kleur = new JButton(); 

    public KleurBlokje(Blokje b) {
        initComponents();
        this.b = b;
        TitledBorder title;
        if(b.isBlancoBlokje())
             title = BorderFactory.createTitledBorder("Blanco blokje");
        else if(b.isGevalideerd())
         title = BorderFactory.createTitledBorder("Gevalideerd blokje");
        else 
             title = BorderFactory.createTitledBorder("Niet Gevalideerd blokje");
       
        this.setBorder(title);
        
        txt_Rood.setText(b.getBackground().getRed()+"");
        txt_Groen.setText(b.getBackground().getGreen()+"");
        txt_Blauw.setText(b.getBackground().getBlue()+"");
        lbl_Rood.setText("R:");
        lbl_Groen.setText("G:");
        lbl_Blauw.setText("B:");
        addListeners();
        this.setLayout(new FlowLayout());
        
        this.add(b);
        this.add(lbl_Rood);   
        this.add(txt_Rood);
        this.add(lbl_Groen);
        this.add(txt_Groen);
        this.add(lbl_Blauw);
        this.add(txt_Blauw);
        
        this.setPreferredSize(new Dimension (400,75));
        
    }
     public void refresh()
    {
        b.bepaalLayout();
      
        txt_Rood.setText(b.getBackground().getRed()+"");
        txt_Groen.setText(b.getBackground().getGreen()+"");
        txt_Blauw.setText(b.getBackground().getBlue()+"");
    }
  
     
    private void addListeners() {
        txt_Rood.addFocusListener(new java.awt.event.FocusAdapter() {

            public void focusLost(java.awt.event.FocusEvent evt) {
                controleer(evt);
            }
        });
        txt_Groen.addFocusListener(new java.awt.event.FocusAdapter() {

            public void focusLost(java.awt.event.FocusEvent evt) {
                controleer(evt);
            }
        });
        txt_Blauw.addFocusListener(new java.awt.event.FocusAdapter() {

            public void focusLost(java.awt.event.FocusEvent evt) {
                controleer(evt);
            }
        });
    }
    
    private void controleer(java.awt.event.FocusEvent evt) {
        if(Integer.parseInt(((JTextField)evt.getSource()).getText())>=0 &&Integer.parseInt(((JTextField)evt.getSource()).getText())<256) 
             b.setBackground(new Color(Integer.parseInt(txt_Rood.getText()),Integer.parseInt(txt_Groen.getText()),Integer.parseInt(txt_Blauw.getText())));

    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    @Override
    public void setNieuweKleur(Color c) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
}
